package com.stack.auto_parts.controller;

import com.stack.auto_parts.common.ApiResult;
import com.stack.auto_parts.entity.Orders;

import com.stack.auto_parts.service.OrderService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @Title: OrderController
 * @Author WUYU_MIN
 * @Package com.stack.auto_parts.controller
 * @Date 2024/7/9 11:06
 * @description:
 */
@CrossOrigin
@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private OrderService orderService;

    @GetMapping("/getputdate")
    public ApiResult<List<Map<String, Object>>> getputdate() {
        List<Map<String, Object>> arraysList = orderService.getputdate();
        return ApiResult.success(arraysList);
    }

    /**
     *
     *     private String partName;
     *     private String supplier;
     *     private Integer number;
     *     private double totalPrice;
     *     private String purchaseName;//采购人，建议从cookie中获取
     * @param orders
     * @return
     */
    @PostMapping("/apply")
    public ApiResult<Void> applyOrder(@RequestBody Orders orders) {
        System.out.println(orders);
        orderService.applyOrderr(orders);
        return ApiResult.success();
    }

    @DeleteMapping("/delete")
    public ApiResult<Void> deleteOrders(@RequestBody String uuid) {
        System.out.println(uuid);
        orderService.deleteOrderr(uuid);
        return ApiResult.success();
    }

    @GetMapping("/list")
    public ApiResult<List<Orders>> list() {
        List<Orders> ordersList = orderService.list();
        return ApiResult.success(ordersList);
    }

    @GetMapping("/listByCondition")
    public ApiResult<List<Orders>> listBycondition(String purchase_name,String partName,String sipplier,String uuid,String state){
        if(Objects.equals(purchase_name, ""))
            purchase_name = null;
        if(Objects.equals(partName, ""))
            partName = null;
        if(Objects.equals(sipplier, ""))
            sipplier =null;
        if(Objects.equals(uuid, ""))
            uuid =null;
        if(Objects.equals(state, ""))
            state =null;
        List<Orders> ordersList = orderService.selectByCondition(purchase_name,partName,sipplier,uuid,state);
        return ApiResult.success(ordersList);
    }

    /**
     * 采购员审核
     * @return
     */
    @PostMapping("/setstatues")
    public ApiResult<Void> setstatues(String uuid,String state,String userName) {
        orderService.statues( uuid, state, userName);
        return ApiResult.success();
    }

    @PostMapping("/mangerset")
    public ApiResult<Void> mangerset(@RequestBody String uuid) {
        orderService.manger(uuid);
        return ApiResult.success();
    }




}
